package test.my.com.myapplicationtest.paint_view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.SurfaceTexture;
import android.util.AttributeSet;
import android.view.TextureView;

import java.lang.ref.SoftReference;

/**
 * Created by ThinkPad on 2016/3/16.
 */
public abstract class DrawView extends TextureView implements TextureView.SurfaceTextureListener{

    protected abstract void beginDraw(Canvas canvas);

    protected void draw(){
        Canvas canvas = lockCanvas();
        beginDraw(canvas);
        unlockCanvasAndPost(canvas);
        SoftReference<String> str = new SoftReference<String>("");
        String a = str.get();
    }

    public DrawView(Context context) {
        super(context);
    }

    public DrawView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DrawView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
        draw();
    }

    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {

    }

    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
        return false;
    }

    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture surface) {

    }
}
